package com.dcjt.firehotcarpad.moudle

import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.view.Window
import android.widget.Toast
import com.amap.api.navi.AMapNavi
import com.amap.api.navi.AMapNaviListener
import com.amap.api.navi.AMapNaviView
import com.amap.api.navi.AMapNaviViewListener
import com.amap.api.navi.model.*
import com.dcjt.firehotcarpad.base.BaseActivity
import com.dcjt.firehotcarpad.manager.DataManager

@SuppressLint("LogNotTimber")
abstract class BaseNaviActivity : BaseActivity(), AMapNaviListener, AMapNaviViewListener {
    protected var mAMapNaviView: AMapNaviView? = null
    protected lateinit var mAMapNavi: AMapNavi
    override fun onCreate(savedInstanceState: Bundle?) {
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        mAMapNavi = AMapNavi.getInstance(applicationContext)
//        val aMapCarInfo = AMapCarInfo()
//        aMapCarInfo.carType = "1"//设置车辆类型，0小车，1货车
//        aMapCarInfo.carNumber = DataManager.getInstance().user.cphm//设置车辆的车牌号码. 如:京DFZ239,京ABZ239
//        aMapCarInfo.vehicleSize = "4"// 设置货车的等级
//        aMapCarInfo.vehicleLoad = "100"//设置货车的总重，单位：吨。
//        aMapCarInfo.vehicleWeight = "99"//设置货车的载重，单位：吨。
//        aMapCarInfo.vehicleLength = "25"//  设置货车的最大长度，单位：米。
//        aMapCarInfo.vehicleWidth = "3"//设置货车的最大宽度，单位：米。 如:1.8，1.5等等。
//        aMapCarInfo.vehicleHeight = "4"//设置货车的高度，单位：米。
//        aMapCarInfo.vehicleAxis = "6"//设置货车的轴数
//        aMapCarInfo.isVehicleLoadSwitch = true//设置车辆的载重是否参与算路
//        aMapCarInfo.isRestriction = false//设置是否躲避车辆限行。
//        mAMapNavi.setCarInfo(aMapCarInfo)
        mAMapNavi.addAMapNaviListener(this)
        mAMapNavi.setUseInnerVoice(true, true)
        super.onCreate(savedInstanceState)
    }

    override fun onResume() {
        super.onResume()
        mAMapNaviView!!.onResume()
    }

    override fun onPause() {
        super.onPause()
        mAMapNaviView!!.onPause()
//        停止导航之后，会触及底层stop，然后就不会再有回调了，但是讯飞当前还是没有说完的半句话还是会说完
//        mAMapNavi.stopNavi();
    }

    override fun onDestroy() {
        super.onDestroy()
        mAMapNaviView!!.onDestroy()
        //since 1.6.0 不再在naviview destroy的时候自动执行AMapNavi.stopNavi();请自行执行
        mAMapNavi.stopNavi()
        mAMapNavi.destroy()
    }

    override fun onInitNaviFailure() {
        Toast.makeText(this, "init navi Failed", Toast.LENGTH_SHORT).show()
    }

    override fun onInitNaviSuccess() {
        //初始化成功
    }

    override fun onStartNavi(type: Int) {
        //开始导航回调
    }

    override fun onTrafficStatusUpdate() {
        //
    }

    override fun onLocationChange(location: AMapNaviLocation) {
        //当前位置回调
    }

    override fun onGetNavigationText(type: Int, text: String) {
        //播报类型和播报文字回调
    }

    override fun onGetNavigationText(s: String) {}
    override fun onEndEmulatorNavi() {
        //结束模拟导航
    }

    override fun onArriveDestination() {
        //到达目的地
    }

    override fun onCalculateRouteFailure(errorInfo: Int) {}
    override fun onReCalculateRouteForYaw() {
        //偏航后重新计算路线回调
    }

    override fun onReCalculateRouteForTrafficJam() {
        //拥堵后重新计算路线回调
    }

    override fun onArrivedWayPoint(wayID: Int) {
        //到达途径点
    }

    override fun onGpsOpenStatus(enabled: Boolean) {
        //GPS开关状态回调
    }

    override fun onNaviSetting() {
        //底部导航设置点击回调
    }

    override fun onNaviMapMode(naviMode: Int) {
        //导航态车头模式，0:车头朝上状态；1:正北朝上模式。
    }

    override fun onNaviCancel() {
        finish()
    }

    override fun onNaviTurnClick() {
        //转弯view的点击回调
    }

    override fun onNextRoadClick() {
        //下一个道路View点击回调
    }

    override fun onScanViewButtonClick() {
        //全览按钮点击回调
    }

    override fun updateCameraInfo(aMapCameraInfos: Array<AMapNaviCameraInfo>) {}
    override fun onServiceAreaUpdate(amapServiceAreaInfos: Array<AMapServiceAreaInfo>) {}
    override fun onNaviInfoUpdate(naviinfo: NaviInfo) {
        //导航过程中的信息更新，请看NaviInfo的具体说明
    }

    override fun OnUpdateTrafficFacility(aMapNaviTrafficFacilityInfo: AMapNaviTrafficFacilityInfo) {
        //已过时
    }

    override fun showCross(aMapNaviCross: AMapNaviCross) {
        //显示放大图回调
    }

    override fun hideCross() {
        //隐藏放大图回调
    }

    override fun showLaneInfo(
        laneInfos: Array<AMapLaneInfo>,
        laneBackgroundInfo: ByteArray,
        laneRecommendedInfo: ByteArray
    ) {
        //显示车道信息
    }

    override fun hideLaneInfo() {
        //隐藏车道信息
    }

    override fun onCalculateRouteSuccess(ints: IntArray) {
        //多路径算路成功回调
    }

    override fun notifyParallelRoad(i: Int) {}
    override fun OnUpdateTrafficFacility(aMapNaviTrafficFacilityInfos: Array<AMapNaviTrafficFacilityInfo>) {
        //更新交通设施信息
    }

    override fun updateAimlessModeStatistics(aimLessModeStat: AimLessModeStat) {
        //更新巡航模式的统计信息
    }

    override fun updateAimlessModeCongestionInfo(aimLessModeCongestionInfo: AimLessModeCongestionInfo) {
        //更新巡航模式的拥堵信息
    }

    override fun onPlayRing(i: Int) {}
    override fun onLockMap(isLock: Boolean) {
        //锁地图状态发生变化时回调
    }

    override fun onNaviViewLoaded() {
        Log.d("wlx", "导航页面加载成功")
        Log.d("wlx", "请不要使用AMapNaviView.getMap().setOnMapLoadedListener();会overwrite导航SDK内部画线逻辑")
    }

    override fun onMapTypeChanged(i: Int) {}
    override fun onNaviViewShowMode(i: Int) {}
    override fun onNaviBackClick(): Boolean {
        return false
    }

    override fun showModeCross(aMapModelCross: AMapModelCross) {}
    override fun hideModeCross() {}
    override fun updateIntervalCameraInfo(
        aMapNaviCameraInfo: AMapNaviCameraInfo,
        aMapNaviCameraInfo1: AMapNaviCameraInfo,
        i: Int
    ) {
    }

    override fun showLaneInfo(aMapLaneInfo: AMapLaneInfo) {}
    override fun onCalculateRouteSuccess(aMapCalcRouteResult: AMapCalcRouteResult) {}
    override fun onCalculateRouteFailure(result: AMapCalcRouteResult) {
        //路线计算失败
        Log.e("dm", "--------------------------------------------")
        Log.i("dm", "路线计算失败：错误码=" + result.errorCode + ",Error Message= " + result.errorDescription)
        Log.i("dm", "错误码详细链接见：http://lbs.amap.com/api/android-navi-sdk/guide/tools/errorcode/")
        Log.e("dm", "--------------------------------------------")
        Toast.makeText(
            this,
            "errorInfo：" + result.errorDetail + ", Message：" + result.errorDescription,
            Toast.LENGTH_LONG
        ).show()
    }

    override fun onNaviRouteNotify(aMapNaviRouteNotifyData: AMapNaviRouteNotifyData) {}

    override fun onGpsSignalWeak(b: Boolean) {}
}